package presentation.util;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;

@SuppressWarnings("serial")
public class ItemButton extends JButton{
	
		private ImageIcon init;
		private ImageIcon pressed;
		private int width;
		private int height;
		private boolean flag;

		public ItemButton(String buttonName) {
			super();
			this.setFocusPainted(false);
			init = new ImageIcon(BasicFrame.class.getResource("/res/item/"+buttonName+"/init.png"));
			pressed = new ImageIcon(BasicFrame.class.getResource("/res/item/"+buttonName+"/pressed.png"
					));
			width = init.getIconWidth();
			height = init.getIconHeight();
		    this.setSize(width, height);
			this.setOpaque(false);
			this.setBorderPainted(false);
			this.setContentAreaFilled(false);
			this.setIcon(init);
			this.addMouseListener(new MouseAdapter() {	
				@Override
				public void mouseClicked(java.awt.event.MouseEvent e) {
					setIcon(pressed);
				}

				@Override
				public void mouseExited(MouseEvent e) {
					if(!flag)
					setIcon(init);
				}
				
				
			});

		}
	  
		
		public void setInit(){
		    setIcon(init);	
		}
		
		public void setPressed(){
			setIcon(pressed);
		}
		
		
		public int getWidth() {
			return width;
		}
		
		public void setFlag(boolean flag){
			this.flag = flag;
		}
}
